package com.lagou.edu;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Response {

    private OutputStream outputStream;

    public Response(OutputStream outputStream){
        this.outputStream = outputStream;
    }

    public void outPut(String text) throws IOException {
        outputStream.write(text.getBytes(StandardCharsets.UTF_8));
        outputStream.flush();
    }

    public void outHtml(String path) throws IOException {
        File file = new File(StreamUtils.getAbsolutePath(path));
        if(file.exists() && file.isFile()){
            StreamUtils.outPutStaticResource(new FileInputStream(file),outputStream);
        }else{
            outPut(HttpProtocolUtil.getFailText());
        }
    }
}
